<template>
   <el-container>
  <el-aside width="200px">

        <SideMenu></SideMenu>
  
  </el-aside>
  <el-container>
    <el-header>
        <strong>我的后台管理系统</strong>
        <div class="header-avatar">
         <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>

         <el-dropdown>
            <span class="el-dropdown-link">
            {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>
                  <router-link :to="{name:'UserCenter'}">个人中心</router-link>
                </el-dropdown-item>
                <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
                
            </el-dropdown-menu>
            </el-dropdown>

            <el-link href="https://markerhub.com" target="_blank">网站</el-link>
            <el-link herf="https://www.bilibili.com/"  target="_blank">B站</el-link>

        </div>
     </el-header>
    <el-main>
      <Tabs></Tabs>
				<div style="margin: 0 15px;">
					<router-view/>
				</div>
    </el-main>
  </el-container>
</el-container>
</template>

<script>
   import SideMenu from "./inc/SideMenu";
   import Tabs from "./inc/Tabs";
    export default {
        name:"Home",
        components:{
            SideMenu,Tabs
        },
        data() {
    return {
      userInfo: {
        id: null,
        username: null,
        avatar: null
      }
    };
  },
  created() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      this.$axios.get("/sys/userInfo").then(res => {
        this.userInfo = res.data.data;
      }).catch(error => {
        console.error("There was an error fetching the user info:", error);
      });
    },
    logout(){
      this.$axios.post("/logout").then(res =>{
        localStorage.clear()
        sessionStorage.clear()

        this.$store.commit("resetState")

        this.$router.push("/login")
      })
    }
  }
};


</script>
<style>
  html, body {
    height: 100%;
    margin: 0;
    padding: 0;
  }
  
  .el-container {
    display: flex;
    flex-direction:row ; 
    min-height: 100vh; 
    padding: 0;
    margin: 0;
  }
     .el-header{
    width:100%;
    background-color: #17B3A3;
    color: #333;
    text-align: center;
    line-height: 60px;

     }
     .header-avatar{
        float:right;
        width:210px;
        display:flex;
        justify-content:space-around;
        align-items:center;
     }
    .el-dropdown-link {
        cursor: pointer;
        color: gray;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    line-height: 200px;
  }
  
  .el-main {
    color: #333;
    /* text-align: center; */
    /* line-height: 160px; */
    padding: 0;
  }
  
  .el-menu-vertical-demo{
    height:100%;
  }
  a{
    text-decoration: none;
  }

</style>